﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.system.workflow.flow_type
{ 

    public partial class type_clone : ModulePage
    {
   

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = num;
            }
            if (this.Page.IsPostBack)
            {
                int num2 = Convert.ToInt32(this.ViewState["FlowId"].ToString());
                int num3 = 0;
                FlowTypeDao dao = new FlowTypeDao();
                FlowProcessDao dao2 = new FlowProcessDao();
                FlowTypeData data = new FlowTypeData();
                DataTable table = dao.SelectByFlowId(base.Conn, num2);
                if (table.Rows.Count > 0)
                {
                    num3 = Convert.ToInt32(table.Rows[0]["FlowSort"].ToString());
                    data.FlowSort = Convert.ToInt32(table.Rows[0]["FlowSort"].ToString());
                    data.FlowNo = Convert.ToInt32(this.txtFlowNo.Text);
                    data.FlowName = this.txtFlowName.Text;
                    data.FormId = Convert.ToInt32(table.Rows[0]["FormId"].ToString());
                    data.FlowDoc = Convert.ToBoolean(table.Rows[0]["FlowDoc"].ToString());
                    data.FlowType = Convert.ToInt32(table.Rows[0]["FlowType"].ToString());
                    if (table.Rows[0]["ManageUser"] != DBNull.Value)
                    {
                        data.ManageUser = table.Rows[0]["ManageUser"].ToString();
                    }
                    if (table.Rows[0]["QueryUser"] != DBNull.Value)
                    {
                        data.QueryUser = table.Rows[0]["QueryUser"].ToString();
                    }
                    if (table.Rows[0]["AutoName"] != DBNull.Value)
                    {
                        data.AutoName = table.Rows[0]["AutoName"].ToString();
                    }
                    data.AutoNum = Convert.ToInt32(table.Rows[0]["AutoNum"].ToString());
                    data.AutoLen = Convert.ToInt32(table.Rows[0]["AutoLen"].ToString());
                    data.AutoEdit = Convert.ToInt32(table.Rows[0]["AutoEdit"].ToString());
                    if (table.Rows[0]["QueryItem"] != DBNull.Value)
                    {
                        data.QueryItem = table.Rows[0]["QueryItem"].ToString();
                    }
                    int num4 = dao.Insert(base.Conn, data);
                    DataTable table2 = dao2.SelectByFlowId(base.Conn, num2);
                    if (table2.Rows.Count > 0)
                    {
                        for (int i = 0; i < table2.Rows.Count; i++)
                        {
                            FlowProcessData data2 = new FlowProcessData();
                            data2.FlowId = num4;
                            data2.PrcsId = Convert.ToInt32(table2.Rows[i]["PrcsId"].ToString());
                            data2.PrcsName = table2.Rows[i]["PrcsName"].ToString();
                            if (table2.Rows[i]["PrcsItem"] != DBNull.Value)
                            {
                                data2.PrcsItem = table2.Rows[i]["PrcsItem"].ToString();
                            }
                            if (table2.Rows[i]["HiddenItem"] != DBNull.Value)
                            {
                                data2.HiddenItem = table2.Rows[i]["HiddenItem"].ToString();
                            }
                            if (table2.Rows[i]["PrcsUser"] != DBNull.Value)
                            {
                                data2.PrcsUser = table2.Rows[i]["PrcsUser"].ToString();
                            }
                            if (table2.Rows[i]["PrcsDept"] != DBNull.Value)
                            {
                                data2.PrcsDept = table2.Rows[i]["PrcsDept"].ToString();
                            }
                            if (table2.Rows[i]["PrcsPriv"] != DBNull.Value)
                            {
                                data2.PrcsPriv = table2.Rows[i]["PrcsPriv"].ToString();
                            }
                            if (table2.Rows[i]["PrcsTo"] != DBNull.Value)
                            {
                                data2.PrcsTo = table2.Rows[i]["PrcsTo"].ToString();
                            }
                            data2.SetLeft = Convert.ToInt32(table2.Rows[i]["SetLeft"].ToString());
                            data2.SetTop = Convert.ToInt32(table2.Rows[i]["SetTop"].ToString());
                            if (table2.Rows[i]["Plugin"] != DBNull.Value)
                            {
                                data2.Plugin = table2.Rows[i]["Plugin"].ToString();
                            }
                            if (table2.Rows[i]["AutoItem"] != DBNull.Value)
                            {
                                data2.AutoItem = table2.Rows[i]["AutoItem"].ToString();
                            }
                            if (table2.Rows[i]["PrcsIn"] != DBNull.Value)
                            {
                                data2.PrcsIn = table2.Rows[i]["PrcsIn"].ToString();
                            }
                            if (table2.Rows[i]["PrcsOut"] != DBNull.Value)
                            {
                                data2.PrcsOut = table2.Rows[i]["PrcsOut"].ToString();
                            }
                            if (table2.Rows[i]["PrcsInSet"] != DBNull.Value)
                            {
                                data2.PrcsInSet = table2.Rows[i]["PrcsInSet"].ToString();
                            }
                            if (table2.Rows[i]["PrcsOutSet"] != DBNull.Value)
                            {
                                data2.PrcsOutSet = table2.Rows[i]["PrcsOutSet"].ToString();
                            }
                            data2.AttachmentFlag = Convert.ToInt32(table2.Rows[i]["AttachmentFlag"].ToString());
                            data2.Feedback = Convert.ToInt32(table2.Rows[i]["Feedback"].ToString());
                            data2.TurnPriv = Convert.ToInt32(table2.Rows[i]["TurnPriv"].ToString());
                            if (table2.Rows[i]["MailTo"] != DBNull.Value)
                            {
                                data2.MailTo = table2.Rows[i]["MailTo"].ToString();
                            }
                            data2.UserFilter = Convert.ToInt32(table2.Rows[i]["UserFilter"].ToString());
                            data2.AutoType = Convert.ToInt32(table2.Rows[i]["AutoType"].ToString());
                            if (table2.Rows[i]["AutoUserOp"] != DBNull.Value)
                            {
                                data2.AutoUserOp = table2.Rows[i]["AutoUserOp"].ToString();
                            }
                            if (table2.Rows[i]["AutoUser"] != DBNull.Value)
                            {
                                data2.AutoUser = table2.Rows[i]["AutoUser"].ToString();
                            }
                            if (table2.Rows[i]["TimeOut"] != DBNull.Value)
                            {
                                data2.TimeOut = Convert.ToInt32(table2.Rows[i]["TimeOut"].ToString());
                            }
                            dao2.Insert(base.Conn, data2);
                        }
                    }
                }
                base.CloseConn();
                string str = string.Empty;
                if (num3 != 0)
                {
                    str = "type_list.aspx?sort_id=" + num3.ToString();
                }
                else
                {
                    str = "type_edit.aspx?flow_id=" + num2.ToString();
                }
                StringBuilder builder = new StringBuilder("<script>\n");
                builder.Append("parent.sort.location.reload();\n");
                builder.Append("location = '" + str + "';\n");
                builder.Append("</script>\n");
                if (!this.Page.IsClientScriptBlockRegistered("flow_type"))
                {
                    this.Page.RegisterClientScriptBlock("flow_type", builder.ToString());
                }
            }
        }
       
    }
}

